package top.wlink.bzgrowup;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;

import top.wlink.bzgrowup.dummy.DummyContent;

public class MainActivity extends AppCompatActivity implements HomeItemFragment.OnListFragmentInteractionListener{

    private TextView mTextMessage;
    private HomeItemFragment mFragmentHome;


    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {

            android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

            switch (item.getItemId()) {
                case R.id.navigation_home:
                    mTextMessage.setText("");

                    if(mFragmentHome==null)
                    {
                        mFragmentHome = HomeItemFragment.newInstance(1);
                    }

                    transaction.replace(R.id.content, mFragmentHome);
                    break;
                case R.id.navigation_dashboard:
                    mTextMessage.setText(R.string.title_dashboard);
                    break;
                case R.id.navigation_settings:
                    mTextMessage.setText(R.string.title_settings);
                    break;
                case R.id.navigation_bzworld:
                    //mTextMessage.setText(R.string.title_bzworld);
                    Intent pushIntent = new Intent();
                    pushIntent.setClass(MainActivity.this, HuaweiPushActivity.class);
                    pushIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(pushIntent);
                    /*
                    ComponentName cn = new ComponentName("top.wlink.bzgrowup","top.wlink.bzgrowup.MainActivity");
                    intent.setComponent(cn);
                    intent.setAction("android.intent.action.MAIN");*/
                    break;

            }
            transaction.commit();
            return true;
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTextMessage = (TextView) findViewById(R.id.message);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    }

    public void onListFragmentInteraction(DummyContent.DummyItem uri){
    }
}
